import { createApp } from 'vue'
import App from './App.vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import './assets/css/pace-theme.css'
import { createRouter, createWebHistory } from 'vue-router'
import { createPinia } from 'pinia'
import cache from '@/utils/cache'
import './assets/css/style.scss'
import './assets/css/script.scss'
import './assets/css/invite.scss'
import './assets/css/certification.scss'
import './assets/css/upload.scss'
import './assets/css/more-style.scss'
import './assets/css/globalTransition.scss'
import './assets/css/menu-style.scss'
import apiRequest from "/src/utils/request/BaseRequest"
import plugins from './common/plugins'
import DialogTopClose from "@/components/TopClose/TopClose"
import LoadingIframe from "@/components/Loading/LoadingIframe"
import ATabs from "@/components/Tabs/Tabs"
import VueMarkdownEditor from '@kangc/v-md-editor'
import '@kangc/v-md-editor/lib/style/base-editor.css'
import vuepressTheme from '@kangc/v-md-editor/lib/theme/vuepress.js'
import '@kangc/v-md-editor/lib/theme/style/vuepress.css'
import './assets/iconfont/iconfont.js'

// ECharts 配置
import ECharts from 'vue-echarts'
import * as echarts from 'echarts/core'
import { BarChart } from 'echarts/charts'
import {
  TitleComponent,
  TooltipComponent,
  GridComponent,
  LegendComponent,
  DataZoomComponent,
  MarkLineComponent,
  MarkPointComponent
} from 'echarts/components'
import { CanvasRenderer } from 'echarts/renderers'

import { copyToClipboard } from '@/utils/util'
import router from './router/index'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import VueVerify from '@/components/verifition/Verify.vue'
import VerifySlide from '@/components/verifition/Verify/VerifySlide.vue'
import VerifyPoints from '@/components/verifition/Verify/VerifyPoints.vue'
import store from './store'

// 注册必需的组件
echarts.use([
  TitleComponent,
  TooltipComponent,
  GridComponent,
  LegendComponent,
  DataZoomComponent,
  MarkLineComponent,
  MarkPointComponent,
  BarChart,
  CanvasRenderer
])

VueMarkdownEditor.use(vuepressTheme)

const app = createApp(App)

// 创建并使用 pinia
const pinia = createPinia()
app.use(pinia)

// 然后是其他插件
app.use(ElementPlus)
app.use(plugins)
app.use(VueMarkdownEditor)
app.use(router)
app.use(store)

// 全局组件注册
app.component('DialogTopClose', DialogTopClose)
app.component('LoadingIframe', LoadingIframe)
app.component('a-tabs', ATabs)
app.component('v-chart', ECharts)
app.component('VueVerify', VueVerify)
app.component('VerifySlide', VerifySlide)
app.component('VerifyPoints', VerifyPoints)

// 全局属性
app.config.globalProperties.$cache = cache
app.config.globalProperties.$api = apiRequest
app.config.globalProperties.$copy = function (value, mes) {
  if (copyToClipboard(value)) {
    ElMessage.success(mes)
  }
}

// 注册所有图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

app.mount('#app')
